﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ue.Eagle..FileSystems;
using Ue.Core.FileSystems.Dependencies;

namespace Ue.Eagle.Tests.Runtime.FileSystem
{
    [TestClass]
    public class DependenciesFolderTests
    {
        private IAppDataFolder appDataFolder;
        private IDependenciesFolder dependenciesFolder;

        [TestInitialize]
        public void Initial()
        {
            this.appDataFolder = new StubAppDataFolder();
            this.dependenciesFolder = new DependenciesFolder(this.appDataFolder);
        }

        [TestMethod]
        public void LoadDescriptorsShouldReturnEmptyList()
        {
            this.appDataFolder.Delete("Dependencies/dependencies.xml", true);

            var e = this.dependenciesFolder.LoadDescriptors();
            Assert.AreEqual(e, Enumerable.Empty<DependencyDescriptor>());
        }

        [TestMethod]
        public void StoreDescriptorsShouldWork()
        {
            var d = new DependencyDescriptor
            {
                Name = "name",
                LoaderName = "test",
                VirtualPath = "~/bin"
            };

            this.dependenciesFolder.StoreDescriptors(new[] { d });
            var e = this.dependenciesFolder.LoadDescriptors();
            Assert.AreEqual(1, e.Count());
            Assert.AreEqual(e.FirstOrDefault().Name, "name"); 
            Assert.AreEqual(e.FirstOrDefault().LoaderName, "test");
            Assert.AreEqual(e.FirstOrDefault().VirtualPath, "~/bin");
        }
    }
}
